package thread;

public class ThreadLocalDemo {
    private static ThreadLocal<User> userManager=new ThreadLocal<User>(){
        public User initialValue(){
            return new User();
        }
    };

    public static User getUser(){
        return userManager.get();
    }

    public static void main(String[] args) throws InterruptedException {
        User user=ThreadLocalDemo.getUser();
        System.out.println(user.getName());
        System.out.println("--------------");
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                User user=ThreadLocalDemo.getUser();
                System.out.println(user.getName());
            }
        });
        thread.start();
        thread.join();
        System.out.println("--------------");

    }

}
